/*
 * Copyright (C) 2009 Rob Cash
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * LocalFileMessageStore.java
 * 
 * Created on Jan 9, 2009 at 8:08:41 PM
 */

package org.robcash.apps.messagepopup.vo.impl;

import java.io.File;
import org.robcash.apps.messagepopup.vo.MessageProvider;
import org.robcash.apps.messagepopup.vo.MessageStore;

/**
 * Message store that stores messages in a file on the locally accessible
 * filesystem
 * @author Rob
 */
public class LocalFileMessageStore extends BaseMessageStore
        implements MessageStore {

    /**
     * Message provider
     */
    private MessageProvider messageProvider;

    /**
     * Create a new local file message store
     * @param location Location in which messages are stored
     */
    public LocalFileMessageStore(LocalFileMessageStoreLocation location) {
        super(location);
    }
    
    /**
     * Get the message provider
     * @return Message provider
     */
    public MessageProvider getMessageProvider() {
        return messageProvider;
    }

    /**
     * Indicates if the message store is valid. The message store is valid if
     * all of the following are true:
     * <ul>
     * <li>The message location can be read</li>
     * <li>More TBD</li>
     * </ul>
     * @return <tt>true</tt> if the message store is valid
     */
    public boolean isValid() {
        File localFile = ((LocalFileMessageStoreLocation) getLocation()).getLocalFile();
        return localFile.canRead();
    }

}
